﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dack_Web2.DTO;
using System.Data.OleDb;

namespace Dack_Web2.DAO
{
    public class UserDAO
    {
        public void Insert(UserDTO tmp)
        {
          
            string str =  "insert into [User] (TenDangNhap, MatKhau, NgayDK) values (@TenDangNhap, @MatKhau, @NgayDK)";
            OleDbParameter[] pr = {new OleDbParameter("@TenDangNhap", tmp.TenDangNhap),
                                   new OleDbParameter("@MatKhau", tmp.MatKhau),
                                   new OleDbParameter("@NgayDK", tmp.NgayDK)};

            Sql_DataProvider.SQL_ExecuteNonQuery(str, pr);
        }

        public void Update(UserDTO tmp)
        {
            
            string str = "update [User] set MatKhau=@MatKhau where TenDangNhap = @TenDangNhap and MaUser=@MaUser";

            OleDbParameter[] para1 ={ new OleDbParameter("@MatKhau", tmp.MatKhau),
                                     new OleDbParameter("@TenDangNhap", tmp.TenDangNhap),
                                     new OleDbParameter("@MaUser", tmp.MaUser)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str,para1);
        }

        public void Delete(UserDTO tmp)
        {
            OleDbConnection cn = Sql_DataProvider.SQLConnect();
            string str = "delete from User where TenDangNhap=@TenDangNhap and MaUser=@MaUser";
            OleDbCommand cmd = new OleDbCommand(str, cn);

            OleDbParameter para1 = new OleDbParameter("@TenDangNhap", tmp.TenDangNhap);
            OleDbParameter para2 = new OleDbParameter("@MaUser", tmp.MaUser);

            cmd.Parameters.Add(para1);
            cmd.Parameters.Add(para2);

            cmd.ExecuteNonQuery();

            cn.Close();
        }
    }
}